package com.chennan.workdir.invoiceapplication.domain.service.impl;

import com.chennan.common.domian.PageInfo;
import com.chennan.workdir.invoiceapplication.api.rest.controller.dto.InvoiceApplicationDTO;
import com.chennan.workdir.invoiceapplication.api.rest.controller.transform.FinanceInvoiceApplicationDTOModelConverter;
import com.chennan.workdir.invoiceapplication.domain.model.InvoiceApplication;
import com.chennan.workdir.invoiceapplication.domain.model.InvoiceApplicationListCondition;
import com.chennan.workdir.invoiceapplication.domain.repository.InvoiceApplicationMapper;
import com.chennan.workdir.invoiceapplication.domain.service.InvoiceApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chennan
 * @createTime 2021年07月27日 12:35:00
 */
@Service
public class InvoiceApplicationServiceImpl implements InvoiceApplicationService {

    @Autowired
    public InvoiceApplicationMapper invoiceApplicationMapper;

    @Autowired
    private FinanceInvoiceApplicationDTOModelConverter converter;

    @Override
    public PageInfo<InvoiceApplicationDTO> listInvoiceApplications(InvoiceApplicationListCondition invoiceApplicationListCondition) {
        List<InvoiceApplication>  list = invoiceApplicationMapper.listInvoiceApplicationByPageInfo(0, 20);
        PageInfo<InvoiceApplicationDTO> objectPageInfo = new PageInfo<>(0, 20);
        List<InvoiceApplicationDTO> invoiceApplicationDTOS = new ArrayList<>();
        list.forEach(item->{
            invoiceApplicationDTOS.add(converter.toDTO(item));
        });
        objectPageInfo.setItems(invoiceApplicationDTOS);
        return objectPageInfo;
    }
}
